package com.cgnpc.scp.purchase.controller;

import cn.com.cgnpc.aep.bizcenter.appcenter.sdk.result.ApiResult;
import com.cgnpc.cud.annotation.OperatorType;
import com.cgnpc.cud.annotation.UBA;
import com.cgnpc.cud.core.domain.AjaxResult;
import com.cgnpc.scp.common.bean.MyPageResult;
import com.cgnpc.scp.common.utils.AjaxResultUtil;
import com.cgnpc.scp.purchase.mybatis.entity.PurchaseAllocation;
import com.cgnpc.scp.purchase.mybatis.entity.ViewCLoseDemand;
import com.cgnpc.scp.purchase.service.ITrackingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/******************************
 * 用途说明: 计划跟踪
 * 作者姓名: chenshijie
 * 创建时间: 2020/12/26 00:36
 ******************************/
@RestController
@RequestMapping("/scp/purchase/tracking")
public class TrackingController {

    private static final Logger LOGGER = LoggerFactory.getLogger(AllocationController.class);

    @Autowired
    private MessageSource messageSource;

    @Autowired
    private ITrackingService trackingService;

    /**********************************
     * 用途说明: 查询分配给当前用户的需求列表
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @PostMapping("/queryUserAllocation")
//    @RequiresPermissions("win_add")
    @UBA(module = "计划跟踪",action = "查询分配给当前用户的需求",channel = OperatorType.Button)
    public AjaxResult queryUserAllocation(HttpServletRequest request, @RequestBody ViewCLoseDemand viewCLoseDemand) {
        try {
            MyPageResult<ViewCLoseDemand> viewDemandQueryMyPageResult  = trackingService.queryUserAllocation(viewCLoseDemand);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,viewDemandQueryMyPageResult);
        } catch (Exception e) {
            LOGGER.error("ContractProcessController insertContract error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 修改需求状态
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @PostMapping("/changeStatus")
//    @RequiresPermissions("win_add")
    @UBA(module = "计划跟踪",action = "修改需求状态",channel = OperatorType.Button)
    public AjaxResult changeStatus(HttpServletRequest request, @RequestBody PurchaseAllocation purchaseAllocation) {
        try {
            ApiResult apiResult = trackingService.changeStatus(purchaseAllocation);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,apiResult);
        } catch (Exception e) {
            LOGGER.error("ContractProcessController insertContract error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

}
